{% extends "admin/base_site.html" %}
{% load i18n %}
{% load taxonomy %}

{% block extrahead %}
<link href="{{media_prefix}}css/taxonomy.css" rel="stylesheet" type="text/css" media="screen"/>
{% if jquery %}
<script type="text/javascript" src="{{jquery}}"></script>
<script type="text/javascript">
// Declare some string so we can use i18n
var detachMessage = '{% trans "Are you sure you want to make this term a root term?" %}';
var deleteMessage = '{% trans "Are you sure you want to delete this term?" %}';
var checkMessage = '{% trans "The taxonomy tree has changed. Do you want to save it before proceeding? (If you cancel, you will loose changes to the tree structure)" %}';
</script>
<script type="text/javascript" src="/media/taxonomy/js/taxonomy.js"></script>
{% endif %}
{% endblock %}

{% block breadcrumbs %}
<div class="breadcrumbs">
    <a href="../">{% trans "Home" %}</a> &rsaquo; {% trans "Taxonomy" %}
</div>
{% endblock %}

{% block content %}
{% if jquery %}
<div id="taxonomy-add-overlay" style="display:none;"></div>
<div id="taxonomy-add-popup" style="display:none;">
    <h2>{% trans "Add New Term" %}</h2>
    <h3 id="taxonomy-add-popup-name-label">{% trans "Term Name" %}</h3>
    <p id="taxonomy-add-popup-name-error"><em>You must specify a name for the term.</em></p>
    <input type="text" style="width:80%" id="term-name-input"/>
    <h3>{% trans "Term Description" %}</h3>
    <textarea rows="5" style="width:80%" id="term-description-input"></textarea>
    <br/>
    <button id="taxonomy-add-cancel">Cancel</button>
    <button id="taxonomy-add-submit">Submit</button>
    <br/>
    <br/>
</div>
<div id="taxonomy-attach-popup" style="display:none;">
    <h2>{% trans "Attach Term" %}</h2>
    <select id="term-attachid-select">
        {% for root in roots %}
            <option value='{{root.id}}'>{{root.name}}</option>
        {% endfor %}
    </select><br/>
    <button id="taxonomy-attach-cancel">Cancel</button>
    <button id="taxonomy-attach-submit">Submit</button>
    <br/>
    <br/>
</div>
{% endif %}
<div id="content-main">
    <ul class="object-tools">
        <li>
            {% if jquery %}
                <a class="addlink" href='' onclick='taxonomy_add_child(0);return false;'>{% trans "Add Root" %}</a>
            {% else %}
                <a class="addlink" href='./term/add'>{% trans "Add Root" %}</a>
            {% endif %}
        </li>
    </ul>
    <div class="module" style="width:500px;">
        <table style="width:100%" summary="{% trans "Model in the Taxonomy application" %}">
            <caption>{% trans "Taxonomy" %}</caption>
            <tr>
                <th scope="row" style="width:100%;"><a href="./term">{% trans "Terms" %}</a></th>
                {% if perms.taxonomy.can_add_term %}
                <td><a class="addlink" href="./term/add">{% trans "Add" %}</a></td>
                {% else %}
                <td>&nbsp;</td>
                {% endif %}
                <td><a class="changelink" href="./term">{% trans "Change" %}</a></td>
            </tr>
            <tr>
                {% if perms.taxonomy.can_change_viewbridge %}
                <th scope="row" style="width:100%;"><a href="./viewbridge">{% trans "View Bridges" %}</a></th>
                {% else %}
                <th scope="row">{% trans "View Bridge" %}</th>
                {% endif %}
                {% if perms.taxonomy.can_add_viewbridge %}
                <td><a class="addlink" href="./viewbridge/add">{% trans "Add" %}</a></td>
                {% else %}
                <td>&nbsp;</td>
                {% endif %}
                {% if perms.taxonomy.can_change_viewbridge %}
                <td><a class="changelink" href="./viewbridge">{% trans "Change" %}</a></td>
                {% else %}
                <td>&nbsp;</td>
                {% endif %}
            </tr>
        </table>
    </div>
    {% if jquery %}
    <div style='height:1em;'></div>
    <div id="changelist" class="module filtered">
        <div id="toolbar">
        </div>
        <div id="taxonomy-terms">
            {% for root in roots %}
                <div id="taxonomy-root-{{root.id}}" class="taxonomy-root">
                    <h2>{{root.name}}
                        <a href='' onclick='taxonomy_add_child({{root.id}}); return false;'>{% trans "Add Term" %}</a>
                        <a href='' onclick='taxonomy_attach_term({{root.id}}); return false;'>{% trans "Attach Root" %}</a>
                    </h2>
                    <div class="taxonomy-admin-list">
                    <ul>
                        {% taxonomy_admin_render_list root 0 %}
                    </ul>
                    </div>
                </div>
            {% endfor %}
            <button onclick='taxonomy_save_tree(); return false;'>{% trans "Save Taxonomy Tree" %}</a>
        </div>
        <div style="clear:both;"></div>
    </div>
    {% endif %}
</div>
{% endblock %}

